package db10;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class BookCollectionExample {
    public static void main(String[] args) {
        List<Book> collection1 = new ArrayList<>();
        collection1.add(new Book(1,20.0,"Fiction","Author A"));
        collection1.add(new Book(2,30.0,"Non-Fiction","Author B"));
        collection1.add(new Book(3,25.0,"Mystery","Author C"));
        collection1.add(new Book(4,15.0,"Fantasy","Author D"));

        List<Book> collection2 = new ArrayList<>();
        collection2.add(new Book(1,20.0,"Fiction","Author A"));
        collection2.add(new Book(5,35.0,"Science","Author E"));


        int duplicates = 0;
        for (Book book1 :collection1){
            for (Book book2 : collection2){
                if (book1.getId()==book2.getId() && book1.getPrize()==book2.getPrize() &&
                book1.getType().equals(book2.getType()) && book1.getAuthor().equals(book2.getAuthor()))
                    duplicates++;
            }
        }
        System.out.println("数据重复的数据个数："+duplicates);
        Iterator<Book> iterator = collection1.iterator();
        while (iterator.hasNext()){
            Book book = iterator.next();
            System.out.println(book);
        }
        for (Book book : collection2){
            System.out.println(book);
        }
    }
}
